package view;
import constant.ConstRole;

import pond.common.FILE;
import pond.common.PATH;
import pond.db.DB;
import pond.db.connpool.ConnectionPool;
import pond.web.InternalMids;
import pond.web.Pond;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Created by sky_wang on 2017/4/7.
 */
public class App {

    public static  List<ConstRole> testGetRoleList () {
        if (true) {
            return new ArrayList<ConstRole>() {
                {
                    add(ConstRole.ROLE_VIEW_CREATED);
                    add(ConstRole.ROLE_VIEW_DELETED);
                    add(ConstRole.ROLE_RELATIONSHIP_UPDATE);
                    add(ConstRole.ROLE_REPORT_DESIGNED);
                    add(ConstRole.ROLE_REPORT_CONSULTED);

                }
            };
        }
        return new ArrayList<ConstRole>() {
            {

                add(ConstRole.ROLE_REPORT_DESIGNED);
                add(ConstRole.ROLE_REPORT_CONSULTED);
            }
        };
    }

    public static void main(String args[]) {

        Properties p = FILE.loadProperties("db.conf");
        DB db= new DB(ConnectionPool.c3p0(p));
        ReportView r = new ReportView(
                db,
                App::testGetRoleList,
                new File(
                        PATH.detectWebRootPath() +File.separator +"src" +File.separator +"main" +File.separator
                                +"resources" +File.separator +"report_data"
                ),
                "/xxx/report_view/"
        );

        Pond.init(app -> {
            System.out.println("/report_view/*");

            app.use("/xxx/report_view/*", r.server());
            //app.use("/report_view/*", r.server(""));
            //app.use("/*", r.server());
            app.otherwise(InternalMids.FORCE_CLOSE);
        }).listen(1234);

    }
}